// by Xeno
//#define __DEBUG__
#define THIS_FILE "fn_artytypeselchanged.sqf"
#include "x_setup.sqf"

#include "x_uiinc.sqf"

private ["_selection", "_control", "_selectedIndex", "_mag", "_wpos", "_warty", "_inrange", "_eta", "_ctrl"];
disableSerialization;
PARAMS_1(_selection);

_control = _selection select 0;
_selectedIndex = _selection select 1;

if (_selectedIndex == -1) exitWith {};

_mag = _control lbData _selectedIndex;

_wpos = markerPos GVAR(ARTI_MARKER_HELPER);

_wpos set [2, 0];

_warty = GVAR(ao_arty_vecs) select 0;

_inrange = _wpos inRangeOfArtillery [[_warty], _mag];

__TRACE_3("","_mag","_wpos","_warty");
__TRACE_1("","_inrange");

_eta = if (_inrange) then {_warty getArtilleryETA [_wpos, _mag]} else {0};

_ctrl = __uiGetVar(D_ARTI_DISP) displayCtrl 900;
_ctrl ctrlSetText format [localize "STR_DOM_MISSIONSTRING_1458", _eta];

_ctrl = __uiGetVar(D_ARTI_DISP) displayCtrl 890;
if (_inrange) then {
	_ctrl ctrlSetText localize "STR_DOM_MISSIONSTRING_1244";
	_ctrl ctrlEnable true;
} else {
	_ctrl ctrlSetText localize "STR_DOM_MISSIONSTRING_1244a";
	_ctrl ctrlEnable false;
};